<template>
  <div class="login-container">
    <video id="myVideo" autoplay muted loop>
      <source src="@/video/loginVideo.mp4" type="video/mp4">
    </video>
    <div class="logo" />
    <div class="form">
      <div class="img">
        <img src="@/images/logo.png" alt="">

      </div>

      <el-card shadow="never" class="login-card">
        <!--登录表单-->
        <el-form ref="form" :model="form" :rules="rules">
          <el-form-item prop="account">
            <!-- <i class="el-icon-edit" /> -->
            <i class="el-icon-user-solid" />
            <el-input v-model="form.account" placeholder="请输入帐号" />
          </el-form-item>
          <el-form-item prop="password">
            <i class="el-icon-unlock" />
            <el-input v-model="form.password" show-password placeholder="请输入密码" />
            <!-- <i class="el-icon-view" /> -->
          </el-form-item>
          <el-form-item prop="key">
            <svg-icon icon-class="yanzhengma" />
            <el-input v-model="form.code" placeholder="请输入验证码" />
            <img :src="imageUrl" alt="" class="code-image" @click="handoff">
          </el-form-item>
          <el-form-item>
            <el-button style="width:328px" type="primary" @click="hLogin">登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>

    </div>
  </div>
</template>
<script>
import { getCaptcha } from '@/api/user'
export default {
  name: 'Login',
  data() {
    return {
      form: {
        account: 'shenlingadmin',
        password: '123456',
        code: '',
        key: 1,
        signPassword: '',
        signAccount: '',
        bindPassword: '',
        bindAccount: '',
        tenant: ''
      },
      imageUrl: '',
      rules: {
        account: [
          { required: true, message: '请输入账号', trigger: 'blur' }
          // { pattern: 'shenlingadmin', message: '账号不正确', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 6, max: 16, message: '密码长度应该为6-16位之间', trigger: 'blur' }
        ]

      }
    }
  },
  async created() {
    const res = await getCaptcha(this.form.key)
    this.blob(res)
  },
  methods: {

    getLogin() {
      alert('发送请求')
    },
    hLogin() {
      this.$refs.form.validate(async(valida) => {
        valida && this.$store.dispatch('user/login', this.form)
      })
    },

    blob(res) {
      const blob = new Blob([res], { type: 'image/png' })
      const imageUrl = URL.createObjectURL(blob)
      const image = new Image()
      image.src = imageUrl
      image.onload = () => {
        this.imageUrl = imageUrl
      }
    },
    async handoff() {
      const res = await getCaptcha(this.form.key)
      this.blob(res)
      // console.log(1)
    }
  }
}
</script>
<style lang="scss">
#myVideo {
  position: fixed;
  right: 0;
  bottom: 0;
  min-width: 100%;
  min-height: 100%;
  z-index: -1
}
.login-container {
  display: flex;
    width: 100%;

  .form {

    position: absolute;
    top: 45%;
    left: 45%;
    margin: -180px 0 0 -160px;
    width: 450px;
    height: 490px;
    padding: 36px 40px;
    background: #fff;
    border-radius: 10px;

    .el-icon-user-solid{
    width: 23px;
    height: 25px;
    position: absolute;
    left: 5px;
    top: 10px;
    z-index: 1;
    font-size: 18px;
    color: #bac0cd;
    }
    .el-icon-unlock{
      width: 23px;
    height: 25px;
    position: absolute;
    left: 5px;
    top: 10px;
    z-index: 1;
    font-size: 18px;
    color: #bac0cd;
    }
    .el-icon-view &befor{
    width: 23px;
    height: 25px;
    position: absolute;
    right: 5px;
    top: 10px;
    z-index: 1;
    font-size: 18px;
    color: #bac0cd;
    }

    .svg-icon{
    width: 20px;
    height: 20px;
    position: absolute;
    left: 2px;
    top: 10px;
    z-index: 1;
    font-size: 18px;
    color: #bac0cd;
    }
    .el-card {
    justify-content: center;
    align-content: center;

    }
    .img{

    position: relative;
    margin-bottom: 28px;
    text-align: center;
    }
    img{
      width: 200px;
      margin: 0 auto;
    }

    .code-image{
    display: inline-block;
    vertical-align: top;
    width: 71px;
    height: 32px;
    cursor: pointer;
    margin-left: 10px;
    position: absolute;
    right: 10px;
    top: 3px;
    }

    .el-input {
      justify-content: center;
      align-content: center;

      //
      height: 44px;
      .el-input__inner {
        background: #f4f5fb;
        padding: 0px 25px;
      }
    }
    .el-checkbox {
      color:#606266;
    }
    .el-button{

      background: #e15536;
    }

  }
}
</style>
